<?php

$oid = (isset($_REQUEST['oid'])) ? $_REQUEST['oid'] : false;
if(!$oid) $lang->put('history-no-oid-set');
else {
	
	$extra = '&oid='.$oid;
	
	?>
	<div class="moduleTopNav">
		<h1><?php $lang->put('history'); ?></h1>
	</div>
	<table class="datatable">
		<thead>
			<tr>
				<td>&nbsp;</td>
				<td><?php $lang->put('revision'); ?></td>
				<td><?php $lang->put('name'); ?></td>
				<td><?php $lang->put('title'); ?></td>
				<td><?php $lang->put('text'); ?></td>
				<td><?php $lang->put('author'); ?></td>
				<td><?php $lang->put('time-created'); ?></td>
			</tr>
		</thead>
		<tbody>
			<?php
			
			$structure = array('version', 'name', 'title', 'text', 'author', 'time_created');
			$module->setStructure($structure);
			
			$sql = "SELECT * FROM ".$db->module('pages')." WHERE original_id = '".addslashes($oid)."' ORDER BY time_created DESC";
			$res = mysql_query($sql);
			$num = mysql_num_rows($res);
			if($num) {
				$i=$num;
				while($row = mysql_fetch_array($res)) {
					
					$publishLink = (!$row['published'] && $module->userCanPublish()) ? '<a href="'.$cosa->system('base-url').'/?m='.$m.'&s='.$s.'&publish='.stripslashes($row['id']).'&oid='.$oid.'" title="'.$lang->get('publish').'"><img src="'.$cosa->system('base-url').'/kernel/files/img/icons/s/play.gif" alt="'.$lang->get('publish').'" /></a>' : '';
					$published = ($row['published']) ? '<img src="'.$cosa->system('base-url').'/kernel/files/img/icons/m/check.gif" alt="'.$lang->get('published').'" title="'.$lang->get('published').'" align="top" />' : '';
					
					$data = array(	'id'				=> stripslashes($row['id'])
									,'version'			=> $lang->get('revision-short').$i
									,'icon'				=> $published.'&nbsp'.$publishLink
									,'name'				=> stripslashes($row['name'])
									,'title'			=> stripslashes($row['title'])
									,'text'				=> substr(strip_tags(stripslashes($row['text'])), 0, 70).'...'
									,'author'			=> $user->authorLink($row['created_by'])
									,'time_created'		=> $cosa->datetime($row['time_created'])
									);
					$module->printTableRow($data, $extra, true, false);
					$i--;
					
				}
			} else {
				$module->printEmptyTableRow($lang->get('no-items-found'));
			}
			
			?>
		</tbody>
	</table>
	<?php

}

?>